Skip to contentSkip to conversation

Change in openvpn[master]: multiproto: move generic event handling code in dedicated files

Openvpn-devel In review its_Giaan (Code Review) 2 participants 23 messages Sep 23, 2024 – Jan 24, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1727098847000.I1e5a84969988e4f027a18658d4ab268c13fbf929@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to review the following change.

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h
M src/openvpn/socket.c

10 files changed, 740 insertions(+), 621 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/1

CMakeLists.txt +2 -0
index ad620fa..38df4ef 100644
@@ -455,6 +455,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index 3784a98..d9cb599 100644
@@ -92,6 +92,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index 6840b1a..3acbdd0 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +17 -592

694 lines not on this page · raw message

src/openvpn/mtcp.h +12 -21
index 886d2cc..e48481a 100644
@@ -30,34 +30,25 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
 void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
 
 
@@ -71,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index e7d742b..d7b4e3b 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -745,7 +745,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -3978,9 +3978,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +3 -2
index e2e5ef6..a25aeda 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -169,8 +170,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

src/openvpn/socket.c +2 -0
index f152071..5c7186e 100644
@@ -1123,7 +1123,9 @@
             /* force binding IPv6-only if an address was specified
              * an it is a IPv6 */
             if (sock->local_host && ai_family == AF_INET6)
+            {
                 v6only = true;
+            }
 
             socket_bind(sock->sd, sock->info.lsa->bind_local,
                         ai_family, "TCP/UDP", v6only);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#2).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

14 files changed, 767 insertions(+), 650 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/2

CMakeLists.txt +2 -0
index 5db207d..d5202da 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index ecb2bcf..4436dbc 100644
@@ -92,6 +92,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.c +2 -2
index 5e56be0..e7518e7 100644
@@ -1659,7 +1659,7 @@
 
 void
 process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
-                  struct link_socket *ls)
+                  struct link_socket *sock)
 {
     if (!c->options.ce.mssfix)
     {
@@ -1693,7 +1693,7 @@
             /* extract TOS from IP header */
             if (flags & PIPV4_PASSTOS)
             {
-                link_socket_extract_tos(ls, &ipbuf);
+                link_socket_extract_tos(sock, &ipbuf);
             }
 #endif
 
src/openvpn/forward.h +4 -3
index 40e718b..c99b779 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
@@ -131,7 +132,7 @@
  *
  * @param c    The context structure which contains the external
  *             network socket from which to read incoming packets.
- * @param ls   The socket where the packet can be read from.
+ * @param sock The socket where the packet can be read from.
  */
 void read_incoming_link(struct context *c, struct link_socket *sock);
 
@@ -201,7 +202,7 @@
  *
  * @param c   The context structure of the VPN tunnel associated with the
  *            packet.
- * @param ls  The socket to be used to send the packet.
+ * @param sock The socket to be used to send the packet.
  */
 void process_outgoing_link(struct context *c, struct link_socket *sock);
 
@@ -308,7 +309,7 @@
 
 
 void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
-                       struct link_socket *ls);
+                       struct link_socket *sock);
 
 bool schedule_exit(struct context *c);
 
src/openvpn/init.c +4 -4
index 575b4d2..4eb286a 100644
@@ -4944,7 +4944,7 @@
 void
 inherit_context_child(struct context *dest,
                       const struct context *src,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     CLEAR(*dest);
 
@@ -4983,7 +4983,7 @@
          * The CM_TOP context does the socket listen(),
          * and the CM_CHILD_TCP context does the accept().
          */
-        dest->c2.accept_from = ls;
+        dest->c2.accept_from = sock;
     }
 
 #ifdef ENABLE_PLUGIN
@@ -5017,13 +5017,13 @@
                        &dest->gc);
 
         /* inherit parent link_socket and tuntap */
-        dest->c2.link_sockets[0] = ls;
+        dest->c2.link_sockets[0] = sock;
 
         ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1,
                        &dest->gc);
         ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info,
                      &dest->gc);
-        *dest->c2.link_socket_infos[0] = ls->info;
+        *dest->c2.link_socket_infos[0] = sock->info;
 
         /* locally override some link_socket_info fields */
         dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
src/openvpn/init.h +1 -1
index 11c32ac..50b38e3 100644
@@ -96,7 +96,7 @@
 
 void inherit_context_child(struct context *dest,
                            const struct context *src,
-                           struct link_socket *ls);
+                           struct link_socket *sock);
 
 void inherit_context_top(struct context *dest,
                          const struct context *src);
src/openvpn/mtcp.c +21 -596

705 lines not on this page · raw message

src/openvpn/mtcp.h +12 -21
index 886d2cc..b9f73d4 100644
@@ -30,34 +30,25 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
+
 void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
 
 
@@ -71,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +2 -2
index 37af88e..5092665 100644
@@ -186,7 +186,7 @@
 
 struct multi_instance *
 multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                              struct link_socket *ls)
+                              struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct mroute_addr real = {0};
@@ -257,7 +257,7 @@
                      * connect-freq but not against connect-freq-initial */
                     reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
 
-                    mi = multi_create_instance(m, &real, ls);
+                    mi = multi_create_instance(m, &real, sock);
                     if (mi)
                     {
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
src/openvpn/mudp.h +2 -2
index b378754..3107cc6 100644
@@ -56,13 +56,13 @@
  * successful, returns the newly created instance.
  *
  * @param m           - The single multi_context structure.
- * @param ls          - Listening socket where this instance is connecting to
+ * @param sock        - Listening socket where this instance is connecting to
  *
  * @return A pointer to a multi_instance if one already existed for the
  *     packet's source address or if one was a newly created successfully.
  *      NULL if one did not yet exist and a new one was not created.
  */
 struct multi_instance *multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                                                     struct link_socket *ls);
+                                                     struct link_socket *sock);
 
 #endif /* ifndef MUDP_H */
src/openvpn/multi.c +13 -13
index e7d742b..fc700de 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -745,7 +745,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -754,7 +754,7 @@
  */
 struct multi_instance *
 multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct multi_instance *mi;
@@ -778,7 +778,7 @@
     }
 
     mi->did_open_context = true;
-    inherit_context_child(&mi->context, &m->top, ls);
+    inherit_context_child(&mi->context, &m->top, sock);
     if (IS_SIG(&mi->context))
     {
         goto err;
@@ -3130,7 +3130,7 @@
 
 void
 multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                    struct link_socket *ls)
+                    struct link_socket *sock)
 {
     struct mroute_addr real = {0};
     struct hash *hash = m->hash;
@@ -3186,7 +3186,7 @@
     mi->context.c2.to_link_addr = &mi->context.c2.from;
 
     /* inherit parent link_socket and link_socket_info */
-    mi->context.c2.link_sockets[0] = ls;
+    mi->context.c2.link_sockets[0] = sock;
     mi->context.c2.link_socket_infos[0]->lsa->actual = m->top.c2.from;
 
     tls_update_remote_addr(mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3336,7 +3336,7 @@
  */
 bool
 multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                            struct link_socket *ls)
+                            struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
 
@@ -3357,7 +3357,7 @@
 #ifdef MULTI_DEBUG_EVENT_LOOP
         printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
 #endif
-        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, ls));
+        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
     }
     else
     {
@@ -3398,7 +3398,7 @@
                 /* nonzero length means that we have a valid, decrypted packed */
                 if (floated && c->c2.buf.len > 0)
                 {
-                    multi_process_float(m, m->pending, ls);
+                    multi_process_float(m, m->pending, sock);
                 }
 
                 process_incoming_link_part2(c, lsi, orig_buf);
@@ -3978,9 +3978,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +7 -6
index 572a7a4..930d6b9 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
@@ -276,7 +277,7 @@
 void multi_top_free(struct multi_context *m);
 
 struct multi_instance *multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                                             struct link_socket *ls);
+                                             struct link_socket *sock);
 
 void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown);
 
@@ -291,7 +292,7 @@
  * updates hashtables in multi_context.
  */
 void multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                         struct link_socket *ls);
+                         struct link_socket *sock);
 
 #define MPP_PRE_SELECT             (1<<0)
 #define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -356,10 +357,10 @@
  *                       when using TCP transport. Otherwise NULL, as is
  *                       the case when using UDP transport.
  * @param mpp_flags    - Fast I/O optimization flags.
- * @param ls           - Socket where the packet was received.
+ * @param sock           - Socket where the packet was received.
  */
 bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                                 struct link_socket *ls);
+                                 struct link_socket *sock);
 
 
 /**
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#3).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

14 files changed, 765 insertions(+), 635 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/3

CMakeLists.txt +2 -0
index 5db207d..d5202da 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index ecb2bcf..4436dbc 100644
@@ -92,6 +92,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.c +2 -2
index 5e56be0..e7518e7 100644
@@ -1659,7 +1659,7 @@
 
 void
 process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
-                  struct link_socket *ls)
+                  struct link_socket *sock)
 {
     if (!c->options.ce.mssfix)
     {
@@ -1693,7 +1693,7 @@
             /* extract TOS from IP header */
             if (flags & PIPV4_PASSTOS)
             {
-                link_socket_extract_tos(ls, &ipbuf);
+                link_socket_extract_tos(sock, &ipbuf);
             }
 #endif
 
src/openvpn/forward.h +2 -1
index 4ff5b04..0415726 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
@@ -308,7 +309,7 @@
 
 
 void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
-                       struct link_socket *ls);
+                       struct link_socket *sock);
 
 bool schedule_exit(struct context *c);
 
src/openvpn/init.c +4 -4
index 575b4d2..4eb286a 100644
@@ -4944,7 +4944,7 @@
 void
 inherit_context_child(struct context *dest,
                       const struct context *src,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     CLEAR(*dest);
 
@@ -4983,7 +4983,7 @@
          * The CM_TOP context does the socket listen(),
          * and the CM_CHILD_TCP context does the accept().
          */
-        dest->c2.accept_from = ls;
+        dest->c2.accept_from = sock;
     }
 
 #ifdef ENABLE_PLUGIN
@@ -5017,13 +5017,13 @@
                        &dest->gc);
 
         /* inherit parent link_socket and tuntap */
-        dest->c2.link_sockets[0] = ls;
+        dest->c2.link_sockets[0] = sock;
 
         ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1,
                        &dest->gc);
         ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info,
                      &dest->gc);
-        *dest->c2.link_socket_infos[0] = ls->info;
+        *dest->c2.link_socket_infos[0] = sock->info;
 
         /* locally override some link_socket_info fields */
         dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
src/openvpn/init.h +1 -1
index 11c32ac..50b38e3 100644
@@ -96,7 +96,7 @@
 
 void inherit_context_child(struct context *dest,
                            const struct context *src,
-                           struct link_socket *ls);
+                           struct link_socket *sock);
 
 void inherit_context_top(struct context *dest,
                          const struct context *src);
src/openvpn/mtcp.c +21 -583

692 lines not on this page · raw message

src/openvpn/mtcp.h +12 -21
index 886d2cc..b9f73d4 100644
@@ -30,34 +30,25 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
+
 void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
 
 
@@ -71,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +2 -2
index 28e1940..6a5f4a3 100644
@@ -186,7 +186,7 @@
 
 struct multi_instance *
 multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                              struct link_socket *ls)
+                              struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct mroute_addr real = {0};
@@ -257,7 +257,7 @@
                      * connect-freq but not against connect-freq-initial */
                     reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
 
-                    mi = multi_create_instance(m, &real, ls);
+                    mi = multi_create_instance(m, &real, sock);
                     if (mi)
                     {
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
src/openvpn/mudp.h +2 -2
index b378754..3107cc6 100644
@@ -56,13 +56,13 @@
  * successful, returns the newly created instance.
  *
  * @param m           - The single multi_context structure.
- * @param ls          - Listening socket where this instance is connecting to
+ * @param sock        - Listening socket where this instance is connecting to
  *
  * @return A pointer to a multi_instance if one already existed for the
  *     packet's source address or if one was a newly created successfully.
  *      NULL if one did not yet exist and a new one was not created.
  */
 struct multi_instance *multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                                                     struct link_socket *ls);
+                                                     struct link_socket *sock);
 
 #endif /* ifndef MUDP_H */
src/openvpn/multi.c +13 -13
index e7d742b..fc700de 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -745,7 +745,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -754,7 +754,7 @@
  */
 struct multi_instance *
 multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct multi_instance *mi;
@@ -778,7 +778,7 @@
     }
 
     mi->did_open_context = true;
-    inherit_context_child(&mi->context, &m->top, ls);
+    inherit_context_child(&mi->context, &m->top, sock);
     if (IS_SIG(&mi->context))
     {
         goto err;
@@ -3130,7 +3130,7 @@
 
 void
 multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                    struct link_socket *ls)
+                    struct link_socket *sock)
 {
     struct mroute_addr real = {0};
     struct hash *hash = m->hash;
@@ -3186,7 +3186,7 @@
     mi->context.c2.to_link_addr = &mi->context.c2.from;
 
     /* inherit parent link_socket and link_socket_info */
-    mi->context.c2.link_sockets[0] = ls;
+    mi->context.c2.link_sockets[0] = sock;
     mi->context.c2.link_socket_infos[0]->lsa->actual = m->top.c2.from;
 
     tls_update_remote_addr(mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3336,7 +3336,7 @@
  */
 bool
 multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                            struct link_socket *ls)
+                            struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
 
@@ -3357,7 +3357,7 @@
 #ifdef MULTI_DEBUG_EVENT_LOOP
         printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
 #endif
-        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, ls));
+        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
     }
     else
     {
@@ -3398,7 +3398,7 @@
                 /* nonzero length means that we have a valid, decrypted packed */
                 if (floated && c->c2.buf.len > 0)
                 {
-                    multi_process_float(m, m->pending, ls);
+                    multi_process_float(m, m->pending, sock);
                 }
 
                 process_incoming_link_part2(c, lsi, orig_buf);
@@ -3978,9 +3978,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +7 -6
index daa972c..966f213 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
@@ -276,7 +277,7 @@
 void multi_top_free(struct multi_context *m);
 
 struct multi_instance *multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                                             struct link_socket *ls);
+                                             struct link_socket *sock);
 
 void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown);
 
@@ -291,7 +292,7 @@
  * updates hashtables in multi_context.
  */
 void multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                         struct link_socket *ls);
+                         struct link_socket *sock);
 
 #define MPP_PRE_SELECT             (1<<0)
 #define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -356,10 +357,10 @@
  *                       when using TCP transport. Otherwise NULL, as is
  *                       the case when using UDP transport.
  * @param mpp_flags    - Fast I/O optimization flags.
- * @param ls           - Socket where the packet was received.
+ * @param sock           - Socket where the packet was received.
  */
 bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                                 struct link_socket *ls);
+                                 struct link_socket *sock);
 
 
 /**
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#4).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

14 files changed, 765 insertions(+), 635 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/4

CMakeLists.txt +2 -0
index 5db207d..d5202da 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index ecb2bcf..4436dbc 100644
@@ -92,6 +92,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.c +2 -2
index 5e56be0..e7518e7 100644
@@ -1659,7 +1659,7 @@
 
 void
 process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
-                  struct link_socket *ls)
+                  struct link_socket *sock)
 {
     if (!c->options.ce.mssfix)
     {
@@ -1693,7 +1693,7 @@
             /* extract TOS from IP header */
             if (flags & PIPV4_PASSTOS)
             {
-                link_socket_extract_tos(ls, &ipbuf);
+                link_socket_extract_tos(sock, &ipbuf);
             }
 #endif
 
src/openvpn/forward.h +2 -1
index 4ff5b04..0415726 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
@@ -308,7 +309,7 @@
 
 
 void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf,
-                       struct link_socket *ls);
+                       struct link_socket *sock);
 
 bool schedule_exit(struct context *c);
 
src/openvpn/init.c +4 -4
index 575b4d2..4eb286a 100644
@@ -4944,7 +4944,7 @@
 void
 inherit_context_child(struct context *dest,
                       const struct context *src,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     CLEAR(*dest);
 
@@ -4983,7 +4983,7 @@
          * The CM_TOP context does the socket listen(),
          * and the CM_CHILD_TCP context does the accept().
          */
-        dest->c2.accept_from = ls;
+        dest->c2.accept_from = sock;
     }
 
 #ifdef ENABLE_PLUGIN
@@ -5017,13 +5017,13 @@
                        &dest->gc);
 
         /* inherit parent link_socket and tuntap */
-        dest->c2.link_sockets[0] = ls;
+        dest->c2.link_sockets[0] = sock;
 
         ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1,
                        &dest->gc);
         ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info,
                      &dest->gc);
-        *dest->c2.link_socket_infos[0] = ls->info;
+        *dest->c2.link_socket_infos[0] = sock->info;
 
         /* locally override some link_socket_info fields */
         dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
src/openvpn/init.h +1 -1
index 11c32ac..50b38e3 100644
@@ -96,7 +96,7 @@
 
 void inherit_context_child(struct context *dest,
                            const struct context *src,
-                           struct link_socket *ls);
+                           struct link_socket *sock);
 
 void inherit_context_top(struct context *dest,
                          const struct context *src);
src/openvpn/mtcp.c +21 -583

692 lines not on this page · raw message

src/openvpn/mtcp.h +12 -21
index 886d2cc..b9f73d4 100644
@@ -30,34 +30,25 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
+
 void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
 
 
@@ -71,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +2 -2
index 37af88e..5092665 100644
@@ -186,7 +186,7 @@
 
 struct multi_instance *
 multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                              struct link_socket *ls)
+                              struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct mroute_addr real = {0};
@@ -257,7 +257,7 @@
                      * connect-freq but not against connect-freq-initial */
                     reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
 
-                    mi = multi_create_instance(m, &real, ls);
+                    mi = multi_create_instance(m, &real, sock);
                     if (mi)
                     {
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
src/openvpn/mudp.h +2 -2
index b378754..3107cc6 100644
@@ -56,13 +56,13 @@
  * successful, returns the newly created instance.
  *
  * @param m           - The single multi_context structure.
- * @param ls          - Listening socket where this instance is connecting to
+ * @param sock        - Listening socket where this instance is connecting to
  *
  * @return A pointer to a multi_instance if one already existed for the
  *     packet's source address or if one was a newly created successfully.
  *      NULL if one did not yet exist and a new one was not created.
  */
 struct multi_instance *multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                                                     struct link_socket *ls);
+                                                     struct link_socket *sock);
 
 #endif /* ifndef MUDP_H */
src/openvpn/multi.c +13 -13
index e7d742b..fc700de 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -745,7 +745,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -754,7 +754,7 @@
  */
 struct multi_instance *
 multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct multi_instance *mi;
@@ -778,7 +778,7 @@
     }
 
     mi->did_open_context = true;
-    inherit_context_child(&mi->context, &m->top, ls);
+    inherit_context_child(&mi->context, &m->top, sock);
     if (IS_SIG(&mi->context))
     {
         goto err;
@@ -3130,7 +3130,7 @@
 
 void
 multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                    struct link_socket *ls)
+                    struct link_socket *sock)
 {
     struct mroute_addr real = {0};
     struct hash *hash = m->hash;
@@ -3186,7 +3186,7 @@
     mi->context.c2.to_link_addr = &mi->context.c2.from;
 
     /* inherit parent link_socket and link_socket_info */
-    mi->context.c2.link_sockets[0] = ls;
+    mi->context.c2.link_sockets[0] = sock;
     mi->context.c2.link_socket_infos[0]->lsa->actual = m->top.c2.from;
 
     tls_update_remote_addr(mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3336,7 +3336,7 @@
  */
 bool
 multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                            struct link_socket *ls)
+                            struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
 
@@ -3357,7 +3357,7 @@
 #ifdef MULTI_DEBUG_EVENT_LOOP
         printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
 #endif
-        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, ls));
+        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
     }
     else
     {
@@ -3398,7 +3398,7 @@
                 /* nonzero length means that we have a valid, decrypted packed */
                 if (floated && c->c2.buf.len > 0)
                 {
-                    multi_process_float(m, m->pending, ls);
+                    multi_process_float(m, m->pending, sock);
                 }
 
                 process_incoming_link_part2(c, lsi, orig_buf);
@@ -3978,9 +3978,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +7 -6
index 5175f90..5ecb86a 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
@@ -276,7 +277,7 @@
 void multi_top_free(struct multi_context *m);
 
 struct multi_instance *multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                                             struct link_socket *ls);
+                                             struct link_socket *sock);
 
 void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown);
 
@@ -291,7 +292,7 @@
  * updates hashtables in multi_context.
  */
 void multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                         struct link_socket *ls);
+                         struct link_socket *sock);
 
 #define MPP_PRE_SELECT             (1<<0)
 #define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -356,10 +357,10 @@
  *                       when using TCP transport. Otherwise NULL, as is
  *                       the case when using UDP transport.
  * @param mpp_flags    - Fast I/O optimization flags.
- * @param ls           - Socket where the packet was received.
+ * @param sock           - Socket where the packet was received.
  */
 bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                                 struct link_socket *ls);
+                                 struct link_socket *sock);
 
 
 /**
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#5).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

13 files changed, 761 insertions(+), 631 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/5

CMakeLists.txt +2 -0
index 5db207d..d5202da 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index ecb2bcf..4436dbc 100644
@@ -92,6 +92,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index 5c2fdb8..924fb17 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/init.c +4 -4
index 3b9dc35..e9352fb 100644
@@ -4898,7 +4898,7 @@
 void
 inherit_context_child(struct context *dest,
                       const struct context *src,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     CLEAR(*dest);
 
@@ -4937,7 +4937,7 @@
          * The CM_TOP context does the socket listen(),
          * and the CM_CHILD_TCP context does the accept().
          */
-        dest->c2.accept_from = ls;
+        dest->c2.accept_from = sock;
     }
 
 #ifdef ENABLE_PLUGIN
@@ -4971,13 +4971,13 @@
                        &dest->gc);
 
         /* inherit parent link_socket and tuntap */
-        dest->c2.link_sockets[0] = ls;
+        dest->c2.link_sockets[0] = sock;
 
         ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1,
                        &dest->gc);
         ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info,
                      &dest->gc);
-        *dest->c2.link_socket_infos[0] = ls->info;
+        *dest->c2.link_socket_infos[0] = sock->info;
 
         /* locally override some link_socket_info fields */
         dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
src/openvpn/init.h +1 -1
index 11c32ac..50b38e3 100644
@@ -96,7 +96,7 @@
 
 void inherit_context_child(struct context *dest,
                            const struct context *src,
-                           struct link_socket *ls);
+                           struct link_socket *sock);
 
 void inherit_context_top(struct context *dest,
                          const struct context *src);
src/openvpn/mtcp.c +21 -583

692 lines not on this page · raw message

src/openvpn/mtcp.h +12 -21
index 886d2cc..b9f73d4 100644
@@ -30,34 +30,25 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
+
 void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
 
 
@@ -71,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +2 -2
index 9e915b2..11fff48 100644
@@ -186,7 +186,7 @@
 
 struct multi_instance *
 multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                              struct link_socket *ls)
+                              struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct mroute_addr real = {0};
@@ -257,7 +257,7 @@
                      * connect-freq but not against connect-freq-initial */
                     reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
 
-                    mi = multi_create_instance(m, &real, ls);
+                    mi = multi_create_instance(m, &real, sock);
                     if (mi)
                     {
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
src/openvpn/mudp.h +2 -2
index b378754..3107cc6 100644
@@ -56,13 +56,13 @@
  * successful, returns the newly created instance.
  *
  * @param m           - The single multi_context structure.
- * @param ls          - Listening socket where this instance is connecting to
+ * @param sock        - Listening socket where this instance is connecting to
  *
  * @return A pointer to a multi_instance if one already existed for the
  *     packet's source address or if one was a newly created successfully.
  *      NULL if one did not yet exist and a new one was not created.
  */
 struct multi_instance *multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                                                     struct link_socket *ls);
+                                                     struct link_socket *sock);
 
 #endif /* ifndef MUDP_H */
src/openvpn/multi.c +12 -12
index d9e6b1f..57eba88 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -751,7 +751,7 @@
  */
 struct multi_instance *
 multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct multi_instance *mi;
@@ -3126,7 +3126,7 @@
 
 void
 multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                    struct link_socket *ls)
+                    struct link_socket *sock)
 {
     struct mroute_addr real = {0};
     struct hash *hash = m->hash;
@@ -3182,7 +3182,7 @@
     mi->context.c2.to_link_addr = &mi->context.c2.from;
 
     /* inherit parent link_socket and link_socket_info */
-    mi->context.c2.link_sockets[0] = ls;
+    mi->context.c2.link_sockets[0] = sock;
     mi->context.c2.link_socket_infos[0]->lsa->actual = m->top.c2.from;
 
     tls_update_remote_addr(mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3332,7 +3332,7 @@
  */
 bool
 multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                            struct link_socket *ls)
+                            struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
 
@@ -3353,7 +3353,7 @@
 #ifdef MULTI_DEBUG_EVENT_LOOP
         printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
 #endif
-        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, ls));
+        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
     }
     else
     {
@@ -3394,7 +3394,7 @@
                 /* nonzero length means that we have a valid, decrypted packed */
                 if (floated && c->c2.buf.len > 0)
                 {
-                    multi_process_float(m, m->pending, ls);
+                    multi_process_float(m, m->pending, sock);
                 }
 
                 process_incoming_link_part2(c, lsi, orig_buf);
@@ -3974,9 +3974,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +7 -6
index a4cea79..bef0b73 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -173,8 +174,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
@@ -275,7 +276,7 @@
 void multi_top_free(struct multi_context *m);
 
 struct multi_instance *multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                                             struct link_socket *ls);
+                                             struct link_socket *sock);
 
 void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown);
 
@@ -290,7 +291,7 @@
  * updates hashtables in multi_context.
  */
 void multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                         struct link_socket *ls);
+                         struct link_socket *sock);
 
 #define MPP_PRE_SELECT             (1<<0)
 #define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -355,10 +356,10 @@
  *                       when using TCP transport. Otherwise NULL, as is
  *                       the case when using UDP transport.
  * @param mpp_flags    - Fast I/O optimization flags.
- * @param ls           - Socket where the packet was received.
+ * @param sock           - Socket where the packet was received.
  */
 bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                                 struct link_socket *ls);
+                                 struct link_socket *sock);
 
 
 /**
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 5: Code-Review-2

(2 comments)

Patchset:

PS5:
build broken

File src/openvpn/multi.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/5daac845_5463efa8 :
PS5, Line 777: m
forgot to update reference to "ls"

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Oct 2024 15:41:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#6).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

13 files changed, 765 insertions(+), 632 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/6

CMakeLists.txt +2 -0
index 5db207d..d5202da 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index ecb2bcf..4436dbc 100644
@@ -92,6 +92,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index 5c2fdb8..924fb17 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/init.c +4 -4
index 771f6fe..53fb682 100644
@@ -4896,7 +4896,7 @@
 void
 inherit_context_child(struct context *dest,
                       const struct context *src,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     CLEAR(*dest);
 
@@ -4935,7 +4935,7 @@
          * The CM_TOP context does the socket listen(),
          * and the CM_CHILD_TCP context does the accept().
          */
-        dest->c2.accept_from = ls;
+        dest->c2.accept_from = sock;
     }
 
 #ifdef ENABLE_PLUGIN
@@ -4969,13 +4969,13 @@
                        &dest->gc);
 
         /* inherit parent link_socket and tuntap */
-        dest->c2.link_sockets[0] = ls;
+        dest->c2.link_sockets[0] = sock;
 
         ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1,
                        &dest->gc);
         ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info,
                      &dest->gc);
-        *dest->c2.link_socket_infos[0] = ls->info;
+        *dest->c2.link_socket_infos[0] = sock->info;
 
         /* locally override some link_socket_info fields */
         dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
src/openvpn/init.h +1 -1
index 11c32ac..50b38e3 100644
@@ -96,7 +96,7 @@
 
 void inherit_context_child(struct context *dest,
                            const struct context *src,
-                           struct link_socket *ls);
+                           struct link_socket *sock);
 
 void inherit_context_top(struct context *dest,
                          const struct context *src);
src/openvpn/mtcp.c +21 -583

692 lines not on this page · raw message

src/openvpn/mtcp.h +15 -21
index ab968e9..b9f73d4 100644
@@ -30,34 +30,28 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +2 -2
index 9e915b2..11fff48 100644
@@ -186,7 +186,7 @@
 
 struct multi_instance *
 multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                              struct link_socket *ls)
+                              struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct mroute_addr real = {0};
@@ -257,7 +257,7 @@
                      * connect-freq but not against connect-freq-initial */
                     reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
 
-                    mi = multi_create_instance(m, &real, ls);
+                    mi = multi_create_instance(m, &real, sock);
                     if (mi)
                     {
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
src/openvpn/mudp.h +2 -2
index b378754..3107cc6 100644
@@ -56,13 +56,13 @@
  * successful, returns the newly created instance.
  *
  * @param m           - The single multi_context structure.
- * @param ls          - Listening socket where this instance is connecting to
+ * @param sock        - Listening socket where this instance is connecting to
  *
  * @return A pointer to a multi_instance if one already existed for the
  *     packet's source address or if one was a newly created successfully.
  *      NULL if one did not yet exist and a new one was not created.
  */
 struct multi_instance *multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                                                     struct link_socket *ls);
+                                                     struct link_socket *sock);
 
 #endif /* ifndef MUDP_H */
src/openvpn/multi.c +13 -13
index d9e6b1f..4fddd62 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -751,7 +751,7 @@
  */
 struct multi_instance *
 multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct multi_instance *mi;
@@ -774,7 +774,7 @@
         generate_prefix(mi);
     }
 
-    inherit_context_child(&mi->context, &m->top, ls);
+    inherit_context_child(&mi->context, &m->top, sock);
     if (IS_SIG(&mi->context))
     {
         goto err;
@@ -3126,7 +3126,7 @@
 
 void
 multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                    struct link_socket *ls)
+                    struct link_socket *sock)
 {
     struct mroute_addr real = {0};
     struct hash *hash = m->hash;
@@ -3182,7 +3182,7 @@
     mi->context.c2.to_link_addr = &mi->context.c2.from;
 
     /* inherit parent link_socket and link_socket_info */
-    mi->context.c2.link_sockets[0] = ls;
+    mi->context.c2.link_sockets[0] = sock;
     mi->context.c2.link_socket_infos[0]->lsa->actual = m->top.c2.from;
 
     tls_update_remote_addr(mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3332,7 +3332,7 @@
  */
 bool
 multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                            struct link_socket *ls)
+                            struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
 
@@ -3353,7 +3353,7 @@
 #ifdef MULTI_DEBUG_EVENT_LOOP
         printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
 #endif
-        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, ls));
+        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
     }
     else
     {
@@ -3394,7 +3394,7 @@
                 /* nonzero length means that we have a valid, decrypted packed */
                 if (floated && c->c2.buf.len > 0)
                 {
-                    multi_process_float(m, m->pending, ls);
+                    multi_process_float(m, m->pending, sock);
                 }
 
                 process_incoming_link_part2(c, lsi, orig_buf);
@@ -3974,9 +3974,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +7 -6
index a4cea79..bef0b73 100644
@@ -37,6 +37,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -173,8 +174,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
@@ -275,7 +276,7 @@
 void multi_top_free(struct multi_context *m);
 
 struct multi_instance *multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                                             struct link_socket *ls);
+                                             struct link_socket *sock);
 
 void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown);
 
@@ -290,7 +291,7 @@
  * updates hashtables in multi_context.
  */
 void multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                         struct link_socket *ls);
+                         struct link_socket *sock);
 
 #define MPP_PRE_SELECT             (1<<0)
 #define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -355,10 +356,10 @@
  *                       when using TCP transport. Otherwise NULL, as is
  *                       the case when using UDP transport.
  * @param mpp_flags    - Fast I/O optimization flags.
- * @param ls           - Socket where the packet was received.
+ * @param sock           - Socket where the packet was received.
  */
 bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                                 struct link_socket *ls);
+                                 struct link_socket *sock);
 
 
 /**
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-MessageType: newpatchset

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 6:

(1 comment)

File src/openvpn/multi.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/46da0fcf_69468398 :
PS5, Line 777: m

Quoted 1 line

forgot to update reference to "ls"

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 23 Oct 2024 12:59:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#10).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

13 files changed, 765 insertions(+), 632 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/10

CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/init.c +4 -4
index 86378f7..4d1cef0 100644
@@ -4923,7 +4923,7 @@
 void
 inherit_context_child(struct context *dest,
                       const struct context *src,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     CLEAR(*dest);
 
@@ -4962,7 +4962,7 @@
          * The CM_TOP context does the socket listen(),
          * and the CM_CHILD_TCP context does the accept().
          */
-        dest->c2.accept_from = ls;
+        dest->c2.accept_from = sock;
     }
 
 #ifdef ENABLE_PLUGIN
@@ -4989,11 +4989,11 @@
         ALLOC_ARRAY_GC(dest->c2.link_sockets, struct link_socket *, 1, &dest->gc);
 
         /* inherit parent link_socket and tuntap */
-        dest->c2.link_sockets[0] = ls;
+        dest->c2.link_sockets[0] = sock;
 
         ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1, &dest->gc);
         ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info, &dest->gc);
-        *dest->c2.link_socket_infos[0] = ls->info;
+        *dest->c2.link_socket_infos[0] = sock->info;
 
         /* locally override some link_socket_info fields */
         dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
src/openvpn/init.h +1 -1
index 11c32ac..50b38e3 100644
@@ -96,7 +96,7 @@
 
 void inherit_context_child(struct context *dest,
                            const struct context *src,
-                           struct link_socket *ls);
+                           struct link_socket *sock);
 
 void inherit_context_top(struct context *dest,
                          const struct context *src);
src/openvpn/mtcp.c +21 -583

692 lines not on this page · raw message

src/openvpn/mtcp.h +15 -21
index ab968e9..b9f73d4 100644
@@ -30,34 +30,28 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+struct context *multi_tcp_context(struct multi_context *m, struct multi_instance *mi);
+
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +62,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/mudp.c +2 -2
index 6137578..c0ae4e8 100644
@@ -186,7 +186,7 @@
 
 struct multi_instance *
 multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                              struct link_socket *ls)
+                              struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct mroute_addr real = {0};
@@ -257,7 +257,7 @@
                      * connect-freq but not against connect-freq-initial */
                     reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
 
-                    mi = multi_create_instance(m, &real, ls);
+                    mi = multi_create_instance(m, &real, sock);
                     if (mi)
                     {
                         hash_add_fast(hash, bucket, &mi->real, hv, mi);
src/openvpn/mudp.h +2 -2
index b378754..3107cc6 100644
@@ -56,13 +56,13 @@
  * successful, returns the newly created instance.
  *
  * @param m           - The single multi_context structure.
- * @param ls          - Listening socket where this instance is connecting to
+ * @param sock        - Listening socket where this instance is connecting to
  *
  * @return A pointer to a multi_instance if one already existed for the
  *     packet's source address or if one was a newly created successfully.
  *      NULL if one did not yet exist and a new one was not created.
  */
 struct multi_instance *multi_get_create_instance_udp(struct multi_context *m, bool *floated,
-                                                     struct link_socket *ls);
+                                                     struct link_socket *sock);
 
 #endif /* ifndef MUDP_H */
src/openvpn/multi.c +13 -13
index 67bb58f..72fd964 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -751,7 +751,7 @@
  */
 struct multi_instance *
 multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                      struct link_socket *ls)
+                      struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
     struct multi_instance *mi;
@@ -774,7 +774,7 @@
         generate_prefix(mi);
     }
 
-    inherit_context_child(&mi->context, &m->top, ls);
+    inherit_context_child(&mi->context, &m->top, sock);
     if (IS_SIG(&mi->context))
     {
         goto err;
@@ -3126,7 +3126,7 @@
 
 void
 multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                    struct link_socket *ls)
+                    struct link_socket *sock)
 {
     struct mroute_addr real = {0};
     struct hash *hash = m->hash;
@@ -3182,7 +3182,7 @@
     mi->context.c2.to_link_addr = &mi->context.c2.from;
 
     /* inherit parent link_socket and link_socket_info */
-    mi->context.c2.link_sockets[0] = ls;
+    mi->context.c2.link_sockets[0] = sock;
     mi->context.c2.link_socket_infos[0]->lsa->actual = m->top.c2.from;
 
     tls_update_remote_addr(mi->context.c2.tls_multi, &mi->context.c2.from);
@@ -3332,7 +3332,7 @@
  */
 bool
 multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance,
-                            const unsigned int mpp_flags, struct link_socket *ls)
+                            const unsigned int mpp_flags, struct link_socket *sock)
 {
     struct gc_arena gc = gc_new();
 
@@ -3353,7 +3353,7 @@
 #ifdef MULTI_DEBUG_EVENT_LOOP
         printf("TCP/UDP -> TUN [%d]\n", BLEN(&m->top.c2.buf));
 #endif
-        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, ls));
+        multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
     }
     else
     {
@@ -3394,7 +3394,7 @@
                 /* nonzero length means that we have a valid, decrypted packed */
                 if (floated && c->c2.buf.len > 0)
                 {
-                    multi_process_float(m, m->pending, ls);
+                    multi_process_float(m, m->pending, sock);
                 }
 
                 process_incoming_link_part2(c, lsi, orig_buf);
@@ -3974,9 +3974,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +7 -6
index 9b6834a..8bf596c 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,8 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using TCP
+                                          *   as external transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
@@ -276,7 +277,7 @@
 void multi_top_free(struct multi_context *m);
 
 struct multi_instance *multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
-                                             struct link_socket *ls);
+                                             struct link_socket *sock);
 
 void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown);
 
@@ -291,7 +292,7 @@
  * updates hashtables in multi_context.
  */
 void multi_process_float(struct multi_context *m, struct multi_instance *mi,
-                         struct link_socket *ls);
+                         struct link_socket *sock);
 
 #define MPP_PRE_SELECT             (1<<0)
 #define MPP_CONDITIONAL_PRE_SELECT (1<<1)
@@ -356,10 +357,10 @@
  *                       when using TCP transport. Otherwise NULL, as is
  *                       the case when using UDP transport.
  * @param mpp_flags    - Fast I/O optimization flags.
- * @param ls           - Socket where the packet was received.
+ * @param sock           - Socket where the packet was received.
  */
 bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags,
-                                 struct link_socket *ls);
+                                 struct link_socket *sock);
 
 
 /**
src/openvpn/multi_io.c new file +619 -0

619 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 10: Code-Review-2

(15 comments)

Patchset:

PS10:
I can't review this when half the patch is really renaming of *ls to *sock. Please split these off to a separate patch that does the renaming, and a patch that does actual code/file structure changes.

File src/openvpn/init.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/9d7d20e0_b9d8d37a :
PS10, Line 4926: struct link_socket *sock)
I agree that we might want to make this uniform across the whole code - that is, change all occurences to struct link_socket *XXX to either *ls or *sock.

But this should not be part of a "L" patchset, which is hard enough to review as it is - so please make this into its own patch.

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/36397026_667042d4 :
PS10, Line 165: multi_tcp_context(struct multi_context *m, struct multi_instance *mi)
we lost the inline bit here by making it a global function. Maybe move it to mtcp.h then, and make it a static inline again?

File src/openvpn/mudp.h:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/9b5c56a3_dce8eb89 :
PS10, Line 66: struct link_socket *sock);
see other comment, please move pure ls/sock renaming to a different patch

File src/openvpn/mudp.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/436366d0_85a29dd3 :
PS10, Line 189: struct link_socket *sock)
and here... without the renaming, there wouldn't be a change to mudp.c at all (much easier to understand)

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/708a3ae7_1bc1f45f :
PS10, Line 178: struct multi_protocol *multi_io; /**< State specific to OpenVPN using TCP
If it's still specific to TCP (as the comment says), why rename it to multi_protocol? This is confusing.

http://gerrit.openvpn.net/c/openvpn/+/763/comment/d2d8645d_1d44dadd :
PS10, Line 280: struct link_socket *sock);
this

http://gerrit.openvpn.net/c/openvpn/+/763/comment/f86883ac_ccce439c :
PS10, Line 295: struct link_socket *sock);
and that

http://gerrit.openvpn.net/c/openvpn/+/763/comment/f67a320c_f48331b4 :
PS10, Line 363: struct link_socket *sock);
and yet another one

File src/openvpn/multi.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/76a11a87_3b464974 :
PS10, Line 754: struct link_socket *sock)
another rename

http://gerrit.openvpn.net/c/openvpn/+/763/comment/0d46a452_d8aea7ce :
PS10, Line 777: inherit_context_child(&mi->context, &m->top, sock);
and this

http://gerrit.openvpn.net/c/openvpn/+/763/comment/a496614d_446989b1 :
PS10, Line 3129: struct link_socket *sock)
here

http://gerrit.openvpn.net/c/openvpn/+/763/comment/cfe09b5a_44dfaba8 :
PS10, Line 3185: mi->context.c2.link_sockets[0] = sock;
and there

http://gerrit.openvpn.net/c/openvpn/+/763/comment/6cee5d39_c8c303fa :
PS10, Line 3335: const unsigned int mpp_flags, struct link_socket *sock)
and here...

http://gerrit.openvpn.net/c/openvpn/+/763/comment/7fd9250d_8fe8e422 :
PS10, Line 3356: multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));
this gets a bit boring

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 10
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 30 Dec 2024 19:16:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#11 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#11).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_protocol since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_protocol_init();
- multi_tcp_free() -> multi_protocol_free();
- multi_tcp_wait() -> multi_protocol_io_wait(); and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

9 files changed, 753 insertions(+), 620 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/11

CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +16 -591

686 lines not on this page · raw message

src/openvpn/mtcp.h +14 -21
index ab968e9..31e9e8d 100644
@@ -30,34 +30,27 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
+struct multi_context;
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_protocol *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +61,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_protocol *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index f426b46..d4294e5 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_protocol_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_protocol_free(m->multi_io);
     }
 }
 
@@ -3975,9 +3975,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +4 -2
index 9b6834a..b07917b 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,9 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_protocol *multi_io;     /**< State specific to OpenVPN using both
+                                          *   TCP and UDP as external
+                                          *   transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +632 -0

632 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 11
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#12 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 11:

(14 comments)

File src/openvpn/init.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/3cd77970_c262e6d2 :
PS10, Line 4926: struct link_socket *sock)

Quoted 1 line

I agree that we might want to make this uniform across the whole code - that is, change all occurenc […]

Done

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/8fab14f7_8836c8e6 :
PS10, Line 165: multi_tcp_context(struct multi_context *m, struct multi_instance *mi)

Quoted 1 line

we lost the inline bit here by making it a global function. Maybe move it to mtcp. […]

made this static inline again and moved to multi_io.h where it gets used, also renamed this 'multi_get_context' since it's what it does.

File src/openvpn/mudp.h:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/1ee1261f_36899e3a :
PS10, Line 66: struct link_socket *sock);

Quoted 1 line

see other comment, please move pure ls/sock renaming to a different patch

Done

File src/openvpn/mudp.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/8f0f41f9_ca89d73c :
PS10, Line 189: struct link_socket *sock)

Quoted 1 line

and here... without the renaming, there wouldn't be a change to `mudp. […]

Done

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/18a4cbd0_54aa4b1c :
PS10, Line 178: struct multi_protocol *multi_io; /**< State specific to OpenVPN using TCP

Quoted 1 line

If it's still specific to TCP (as the comment says), why rename it to multi_protocol? This is c […]

It gets used also by UDP, the comment was a leftover.

http://gerrit.openvpn.net/c/openvpn/+/763/comment/048d18f2_978d730d :
PS10, Line 280: struct link_socket *sock);

Quoted 1 line

this

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/bd02fcba_e322ec4d :
PS10, Line 295: struct link_socket *sock);

Quoted 1 line

and that

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/9169a686_317e9b71 :
PS10, Line 363: struct link_socket *sock);

Quoted 1 line

and yet another one

Done

File src/openvpn/multi.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/d56445cb_e795fd77 :
PS10, Line 754: struct link_socket *sock)

Quoted 1 line

another rename

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/a0585c59_7f074ee2 :
PS10, Line 777: inherit_context_child(&mi->context, &m->top, sock);

Quoted 1 line

and this

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/aa433935_03f4722e :
PS10, Line 3129: struct link_socket *sock)

Quoted 1 line

here

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/d202b209_59ae6a8b :
PS10, Line 3185: mi->context.c2.link_sockets[0] = sock;

Quoted 1 line

and there

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/78a7791f_6b0bda67 :
PS10, Line 3335: const unsigned int mpp_flags, struct link_socket *sock)

Quoted 1 line

and here...

Done

http://gerrit.openvpn.net/c/openvpn/+/763/comment/4849bfa6_a38eaef1 :
PS10, Line 3356: multi_set_pending(m, multi_get_create_instance_udp(m, &floated, sock));

Quoted 1 line

this gets a bit boring

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 11
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 09 Jan 2025 13:50:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#13 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 12: Code-Review-1

(2 comments)

Patchset:

PS12:
much better and much easier reviewed now.

As discussed on IRC, the multi_protocol_...() function names are slightly confusing, and I suggest to use multi_io_...(), which is in line with the m->mtcp to m->m_multi_io renaming and also the file names...

File src/openvpn/mtcp.c:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/506eec5d_80c39ac0 :
PS10, Line 165: multi_tcp_context(struct multi_context *m, struct multi_instance *mi)

Quoted 1 line

made this static inline again and moved to multi_io. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 12
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 23 Jan 2025 15:54:58 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#14 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, its_Giaan, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#13).

The following approvals got outdated and were removed:
Code-Review-1 by cron2

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_io since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_io_init();
- multi_tcp_free() -> multi_io_free();
- multi_tcp_wait() -> multi_io_wait();
and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

9 files changed, 753 insertions(+), 620 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/13

CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +16 -591

686 lines not on this page · raw message

src/openvpn/mtcp.h +14 -21
index ab968e9..0da0a7d 100644
@@ -30,34 +30,27 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
+struct multi_context;
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_io *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +61,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_io *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index f426b46..3f55dd7 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_io_free(m->multi_io);
     }
 }
 
@@ -3975,9 +3975,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +4 -2
index 9b6834a..dd29b43 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,9 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_io *multi_io;     /**< State specific to OpenVPN using both
+                                    *   TCP and UDP as external
+                                    *   transport. */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +632 -0

632 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 13
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#15 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 13:

(2 comments)

Patchset:

PS13:
close :-) (the code compiles and passes light tests, but there is a comment that is more confusing than helpful)

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/d62d69ef_43444458 :
PS13, Line 180: * transport. */
getting close... but this comment does not make sense. What is it that is stored here? Are there other protocols but UDP and TCP?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 13
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 23 Jan 2025 17:50:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#16 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

cron2 has removed a vote from this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Removed Code-Review-2 by flichtenheld <[email protected]...>
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 13
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: deleteVote

#17 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/763?usp=email

to look at the new patch set (#14).

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_io since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_io_init();
- multi_tcp_free() -> multi_io_free();
- multi_tcp_wait() -> multi_io_wait();
and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

9 files changed, 751 insertions(+), 620 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/14

CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +16 -591

686 lines not on this page · raw message

src/openvpn/mtcp.h +14 -21
index ab968e9..0da0a7d 100644
@@ -30,34 +30,27 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
+struct multi_context;
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_io *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +61,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_io *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index f426b46..3f55dd7 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_io_free(m->multi_io);
     }
 }
 
@@ -3975,9 +3975,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +2 -2
index 9b6834a..eacfb52 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,7 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_io *multi_io;     /**< I/O state and events tracker */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +632 -0

632 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 14
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#18 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 14:

(1 comment)

File src/openvpn/multi.h:

http://gerrit.openvpn.net/c/openvpn/+/763/comment/abe81f56_aadfe850 :
PS13, Line 180: * transport. */

Quoted 1 line

getting close... but this comment does not make sense. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 14
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 24 Jan 2025 11:46:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#19 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

Patch Set 14: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 14
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 24 Jan 2025 11:51:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#20 lore raw

PATCH v14 1/1 multiproto: move generic event handling code in dedicated files

In reply to a message not in the archive

From: Gianmarco De Gregori <[email protected]...>

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_io since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_io_init();
- multi_tcp_free() -> multi_io_free();
- multi_tcp_wait() -> multi_io_wait();
and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/763
This mail reflects revision 14 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +16 -591

686 lines not on this page · raw message

src/openvpn/mtcp.h +14 -21
index ab968e9..0da0a7d 100644
@@ -30,34 +30,27 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
+struct multi_context;
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_io *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +61,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_io *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index f426b46..3f55dd7 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_io_free(m->multi_io);
     }
 }
 
@@ -3975,9 +3975,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +2 -2
index 9b6834a..eacfb52 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,7 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_io *multi_io;     /**< I/O state and events tracker */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +632 -0

632 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

#21 lore raw

[Openvpn-devel] [PATCH applied] Re: multiproto: move generic event handling code in dedicated files

Basically this patch is just "moving code around" and renaming things with "_tcp_" in them to "_io_", generalizing the "store things" structure to be used for TCP and UDP now. I argued the "_protocol_" part of earlier versions away ("HTTPS is also a 'protocol'") and I think the current version is good enough to move forward.

I've stared a lot at the code, and ran various versions on the client/server testbed - and they all passed all tests.

"git show --color-moved=zebra" is only half-helpful due to all the renaming - but it does help to feel reasonably secure that this is still doing the same thing.

Your patch has been applied to the master branch.

commit cbb0440ee884ba3c052066d915d6fd7ce86befd2

Author: Gianmarco De Gregori
Date:   Fri Jan 24 12:58:48 2025 +0100
     multiproto: move generic event handling code in dedicated files

     Signed-off-by: Gianmarco De Gregori <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg30561.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#22 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#15) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_io since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_io_init();
- multi_tcp_free() -> multi_io_free();
- multi_tcp_wait() -> multi_io_wait();
and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30561.html

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

9 files changed, 751 insertions(+), 620 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/763/15

CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +16 -591

686 lines not on this page · raw message

src/openvpn/mtcp.h +14 -21
index ab968e9..0da0a7d 100644
@@ -30,34 +30,27 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
+struct multi_context;
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_io *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +61,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_io *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index f426b46..3f55dd7 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_io_free(m->multi_io);
     }
 }
 
@@ -3975,9 +3975,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +2 -2
index 9b6834a..eacfb52 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,7 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_io *multi_io;     /**< I/O state and events tracker */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +632 -0

632 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 15
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#23 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/763?usp=email )

Change subject: multiproto: move generic event handling code in dedicated files
......................................................................

multiproto: move generic event handling code in dedicated files

Introduced multi_io.h and multi_io.c files to centralize all codes related to multiple protocols.

Renamed the struct mtcp to struct multi_io since it encompasses the event_set used by the parent context in server mode.

Several methods have also been renamed and moved to fit the multiproto structure:

- multi_tcp_init() -> multi_io_init();
- multi_tcp_free() -> multi_io_free();
- multi_tcp_wait() -> multi_io_wait();
and so forth.

Change-Id I1e5a84969988e4f027a18658d4ab268c13fbf929

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30561.html

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/openvpn/multi.c
M src/openvpn/multi.h
A src/openvpn/multi_io.c
A src/openvpn/multi_io.h

9 files changed, 751 insertions(+), 620 deletions(-)
CMakeLists.txt +2 -0
index 9ffcc89..ea8d006 100644
@@ -458,6 +458,8 @@
     src/openvpn/mudp.h
     src/openvpn/multi.c
     src/openvpn/multi.h
+    src/openvpn/multi_io.h
+    src/openvpn/multi_io.c
     src/openvpn/ntlm.c
     src/openvpn/ntlm.h
     src/openvpn/occ.c
src/openvpn/Makefile.am +1 -0
index d6d6592..37af683 100644
@@ -93,6 +93,7 @@
 	mtu.c mtu.h \
 	mudp.c mudp.h \
 	multi.c multi.h \
+	multi_io.c multi_io.h \
 	networking_freebsd.c \
 	networking_iproute2.c networking_iproute2.h \
 	networking_sitnl.c networking_sitnl.h \
src/openvpn/forward.h +1 -0
index ca2a695..214a322 100644
@@ -50,6 +50,7 @@
 #include "openvpn.h"
 #include "occ.h"
 #include "ping.h"
+#include "multi_io.h"
 
 #define IOW_TO_TUN          (1<<0)
 #define IOW_TO_LINK         (1<<1)
src/openvpn/mtcp.c +16 -591

686 lines not on this page · raw message

src/openvpn/mtcp.h +14 -21
index ab968e9..0da0a7d 100644
@@ -30,34 +30,27 @@
 
 #include "event.h"
 
-/*
- * Extra state info needed for TCP mode
- */
-struct multi_tcp
-{
-    struct event_set *es;
-    struct event_set_return *esr;
-    int n_esr;
-    int maxevents;
-    unsigned int tun_rwflags;
-#ifdef ENABLE_MANAGEMENT
-    unsigned int management_persist_flags;
-#endif
-};
-
+struct multi_context;
 struct multi_instance;
 struct context;
 
-struct multi_tcp *multi_tcp_init(int maxevents, int *maxclients);
-
-void multi_tcp_free(struct multi_tcp *mtcp);
-
-void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi);
+void multi_tcp_dereference_instance(struct multi_io *multi_io, struct multi_instance *mi);
 
 bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi);
 
 void multi_tcp_instance_specific_free(struct multi_instance *mi);
 
+void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi);
+
+bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags);
+
+bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags);
+
+struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls);
+
+void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
+
+
 /**************************************************************************/
 /**
  * Main event loop for OpenVPN in TCP server mode.
@@ -68,6 +61,6 @@
 void tunnel_server_tcp(struct context *top);
 
 
-void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event);
+void multi_tcp_delete_event(struct multi_io *multi_io, event_t event);
 
 #endif /* ifndef MTCP_H */
src/openvpn/multi.c +6 -6
index f426b46..3f55dd7 100644
@@ -440,7 +440,7 @@
      */
     if (tcp_mode)
     {
-        m->mtcp = multi_tcp_init(t->options.max_clients, &m->max_clients);
+        m->multi_io = multi_io_init(t->options.max_clients, &m->max_clients);
     }
     m->tcp_queue_limit = t->options.tcp_queue_limit;
 
@@ -665,9 +665,9 @@
             mi->did_iroutes = false;
         }
 
-        if (m->mtcp)
+        if (m->multi_io)
         {
-            multi_tcp_dereference_instance(m->mtcp, mi);
+            multi_tcp_dereference_instance(m->multi_io, mi);
         }
 
         mbuf_dereference_instance(m->mbuf, mi);
@@ -742,7 +742,7 @@
         initial_rate_limit_free(m->initial_rate_limiter);
         multi_reap_free(m->reaper);
         mroute_helper_free(m->route_helper);
-        multi_tcp_free(m->mtcp);
+        multi_io_free(m->multi_io);
     }
 }
 
@@ -3975,9 +3975,9 @@
 management_delete_event(void *arg, event_t event)
 {
     struct multi_context *m = (struct multi_context *) arg;
-    if (m->mtcp)
+    if (m->multi_io)
     {
-        multi_tcp_delete_event(m->mtcp, event);
+        multi_tcp_delete_event(m->multi_io, event);
     }
 }
 
src/openvpn/multi.h +2 -2
index 9b6834a..eacfb52 100644
@@ -38,6 +38,7 @@
 #include "pool.h"
 #include "mudp.h"
 #include "mtcp.h"
+#include "multi_io.h"
 #include "perf.h"
 #include "vlan.h"
 #include "reflect_filter.h"
@@ -174,8 +175,7 @@
     struct mbuf_set *mbuf;      /**< Set of buffers for passing data
                                  *   channel packets between VPN tunnel
                                  *   instances. */
-    struct multi_tcp *mtcp;     /**< State specific to OpenVPN using TCP
-                                 *   as external transport. */
+    struct multi_io *multi_io;     /**< I/O state and events tracker */
     struct ifconfig_pool *ifconfig_pool;
     struct frequency_limit *new_connection_limiter;
     struct initial_packet_rate_limit *initial_rate_limiter;
src/openvpn/multi_io.c new file +632 -0

632 lines not on this page · raw message

src/openvpn/multi_io.h new file +77 -0

77 lines not on this page · raw message

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/763?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e5a84969988e4f027a18658d4ab268c13fbf929
Gerrit-Change-Number: 763
Gerrit-PatchSet: 15
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged